@isTest 
private class TestQuickAppRequest_WS {
	
	/****Condition for finding ID in Account****/
	static testMethod void duplicateAccount(){
		
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
    	test.startTest();
    	String duplicateAccount = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUser','TestLast','abcd1@ddd.com','Arizona','Bachelor of Science in Accounting','03/2013','Uncontacted','',testAccount.Account_Id__C,'(234) 343-2345');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(duplicateAccount.contains('Success'));
	}
	
	/****Condition for finding ID in Lead****/
	static testMethod void duplicateLead(){ 
		/*Creating Test Database*/
		Lead testLead = TestDatabaseCMS.createLeadForTesting();
		West_Case_Names__c testCaseName = TestDatabaseCMS.createWestCaseNames();
		
		String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
		
		Case testCaseDataset = new Case(RecordTypeId=caseRecordType,Subject='TestCase1',Description='TestDesc',
    	lead__c=testLead.Id,Case_Name__c='Academic Probation');
    	insert testCaseDataset;
		
		/*Testing*/
		test.startTest();
    	String duplicateLead = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestLUser','TestLead','ssss@yyyy.com','Arizona','Bachelor of Science in Accounting','03/2013','Uncontacted','',testLead.Lead_Id__C,'(234) 343-2345');
		test.stopTest();
		
		/*Asserting correctness*/
		System.assert(duplicateLead.contains('Success'));
	}
	
	/****Condition for not finding ID in Salesforce****/
	static testMethod void noDuplicate(){
		/*Creating Test Database*/
		//Lead testLead = TestDatabaseCMS.createLeadForTesting();
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		//Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
		test.startTest();
    	String noDuplicate = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUserD','TestLeadP','ssss3@yyyy.com','Arizona','Bachelor of Science in Accounting','03/2013','Uncontacted','','ksksksksk','(234) 343-2345');
		test.stopTest();
		
		/*Asserting correctness*/
		System.assert(noDuplicate.contains('Failure'));
	}
	
	/****Condition for no matching program****/
	static testMethod void noProgramERR(){
		/*Creating Test Database*/
		Lead testLead = TestDatabaseCMS.createLeadForTesting();
		//Program__c programName = TestDatabaseCMS.createProgramForTesting();
		//Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
		test.startTest();
    	String noProgramERR = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUserD','TestLeadP','ssss3@yyyy.com','Arizona','Bachelor of English in Accounting','03/2013','Uncontacted','',testLead.Lead_Id__C,'(234) 343-2345');
		test.stopTest();
		
		/*Asserting correctness*/
		System.assert(noProgramERR.contains('Failure'));
	}
	
	/****Condition for date format not matching ****/
	static testMethod void dateFormatERR(){
		/*Creating Test Database*/
		//Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		Lead testLead = TestDatabaseCMS.createLeadForTesting();
		
		/*Testing*/
		test.startTest();
		String errorDateFormat = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUserDer','TestLeadP','ssss3@yyyy.com','Arizona','Bachelor of Science in Accounting','03-2013','Uncontacted','',testLead.Lead_Id__C,'(234) 343-2345');
		String errorDateFormat2 = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUserD','TestLeadP','ssss3@yyyy.com','Arizona','Bachelor of Science in Accounting','03/-2013','Uncontacted','',testLead.Lead_Id__C,'(234) 343-2345');
		String errorDateFormat3 = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestLUser','TestLead','ssss@yyyy.com','Arizona','Bachelor of Science in Accounting','03/-2013','Uncontacted','',testAccount.Account_Id__C,'(234) 343-2345');
    	test.stopTest();
    	
    	/*Asserting correctness*/
    	System.assert(errorDateFormat.contains('Failure'));
    	System.assert(errorDateFormat2.contains('Failure'));
    	System.assert(errorDateFormat3.contains('Failure'));
	}
	
	/****Condition for Phone format not matching****/
	static testMethod void phoneFormatERR(){
		/*Creating Test Database*/
		Program__c programName = TestDatabaseCMS.createProgramForTesting();
		Account testAccount = TestDatabaseCMS.createAccountForTesting();
		
		/*Testing*/
    	test.startTest();
    	String phoneFormatERR = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUser','TestLast','abcd1@ddd.com','Arizona','Bachelor of Science in Accounting','03/2013','Uncontacted','',testAccount.Account_Id__C,'(234) &*22343-2s345');
		test.stopTest();
		
		/*Asserting correctness*/
    	System.assert(phoneFormatERR.contains('Failure'));
	}
	
	/****Condition with missing fields ****/
	static testMethod void missingFields(){
		/*Testing*/
		test.startTest();
		String missingFields = QuickAppRequest_WS.convertLeadOrUpdateAccount('TestUserDer','TestLeadP','ssss3@yyyy.com','','Bachelor of Science in Accounting','','Uncontacted','','dsdg3435433dx','(234) 343-2345');
		
		/*Asserting correctness*/
    	System.assert(missingFields.contains('Failure'));
	}
}